package cn.bonoon.kernel.web.handlers;

import cn.bonoon.handler.impl.StandardAutoManager;
import cn.bonoon.kernel.descriptors.ObjectDescriptor;
import cn.bonoon.kernel.support.OperandSupport;
import cn.bonoon.kernel.support.entities.Persistable;
import cn.bonoon.kernel.support.services.IService;
import cn.bonoon.kernel.web.controllers.BaseButtonResolver;
import cn.bonoon.kernel.web.controllers.GridButtonResolver;
import cn.bonoon.kernel.web.html.form.StandardDetailBuilder;
import cn.bonoon.kernel.web.html.form.FormBuilder;

/**
 * <pre>
 * 弹出查看详细信息的对话框
 * 应该在控制器{@link cn.bonoon.kernel.web.controllers.AbstractGridController AbstractLayoutGridController}或其子类
 * 里创建并初始化并注册到{@link cn.bonoon.kernel.web.controllers.AbstractGridController#handlers handlers}对象列表里
 * </pre>
 * @author jackson
 *
 * @param <E>
 * 
 * @see AbstractExecuteHandler
 * @see AbstractDialogHandler
 * @see AbstractDialogFormableHandler
 */
public class DialogDetailHandler<E extends Persistable> extends AbstractDialogFormableHandler<E>{

	public DialogDetailHandler(HandlerRegister register, IService<E> service, Class<?> detailClass) throws Exception {
		super(register, service, detailClass);
		set("查看信息", true);
	}

	@Override
	protected FormBuilder builder(ObjectDescriptor objectDescriptor, StandardAutoManager manager) {
		return new StandardDetailBuilder(objectDescriptor, manager);
	}
	
	@Override
	public BaseButtonResolver register(BaseButtonResolver resolver) throws Exception {
		resolver.setKey(OperandSupport.DIALOG_DETAIL);
		resolver.setName("查看");
		return super.register(resolver);
	}

	public static <E extends Persistable> GridButtonResolver button(HandlerRegister register, IService<E> service, Class<?> detailClass)throws Exception{
		DialogDetailHandler<E> ddh = new DialogDetailHandler<E>(register, service, detailClass);
		GridButtonResolver gbr = register.button();
		ddh.register(gbr);
		return gbr;
	}
}
